home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 April: Mac OS SDK / Dev.CD Apr 98 SDK2.toast / Development Kits (Disc 2) / ScriptX / Documentation / Code Examples from Docs / compguid / twodgrfx / shadshap.sx < prev    next >
Encoding:
Text File  |  1996-05-21  |  3.1 KB  |  160 lines  |  [TEXT/ttxt]

  1. --<<<
  2.  
  3. class BetterShadowedShapeSuper (TwoDPresenter)
  4.     instance variables
  5.     fill
  6.     stroke:blackbrush
  7.     shadowFill:(new brush color:bluecolor)
  8.     shadowStroke:blackbrush
  9.     shadowXoffset:5
  10.     shadowYoffset:-5
  11. end
  12.  
  13.  
  14. class BetterShadowedShape (BetterShadowedShapeSuper)
  15. end
  16.  
  17.  
  18. method init self {class BetterShadowedShape} #rest args #key \
  19.         target:(new Rect x2:50 y2:50) ->
  20. (
  21.     local boundary := new Rect \
  22.            x2:(target.width + abs (self.shadowXoffset)) \
  23.           y2:(target.height + abs(self.shadowYoffset))
  24.       apply NextMethod self boundary:boundary target:target args
  25. )
  26.  
  27.  
  28. method updateBoundary self {class BetterShadowedShape} ->
  29. (
  30.     local target := self.target
  31.     self.boundary := new Rect \
  32.            x2:(target.width + abs (self.shadowXoffset)) \
  33.           y2:(target.height + abs(self.shadowYoffset))
  34.   )
  35.  
  36.  
  37.  
  38.  
  39. method heightSetter self {class BetterShadowedShape} value ->
  40. (
  41.     self.target.height := value
  42.     updateBoundary self 
  43.     notifyChanged self true
  44. )
  45.  
  46. method widthSetter self {class BetterShadowedShape} value ->
  47. (
  48.     self.target.width := value
  49.     updateBoundary self 
  50.     notifyChanged self true
  51. )
  52.  
  53. method heightGetter self {class BetterShadowedShape} ->
  54. (
  55.     self.target.height
  56.     )
  57.     
  58. method widthGetter self {class BetterShadowedShape} ->
  59. (
  60.     self.target.width
  61.     )
  62.  
  63. method fillSetter self {class BetterShadowedShape} value ->
  64. (
  65.     nextMethod self value
  66.     notifychanged self true
  67.     value
  68. )
  69.     
  70.  
  71. method strokeSetter self {class BetterShadowedShape} value ->
  72. (
  73.     nextMethod self value
  74.     notifychanged self true
  75.     value
  76. )
  77.     
  78.  
  79. method shadowfillSetter self {class BetterShadowedShape} value ->
  80. (
  81.     nextMethod self value
  82.     notifychanged self true
  83.     true
  84. )
  85.     
  86.  
  87. method shadowStrokeSetter self {class BetterShadowedShape} value ->
  88. (
  89.     nextMethod self value
  90.     notifychanged self true
  91.     value
  92. )
  93.     
  94.  
  95. method shadowXoffsetSetter self {class BetterShadowedShape} value ->
  96. (
  97.     nextMethod self value
  98.     updateBoundary self 
  99.     notifychanged self true
  100.     value
  101. )
  102.  
  103. method shadowYoffsetSetter self {class BetterShadowedShape} value ->
  104. (
  105.     nextMethod self value
  106.     updateBoundary self 
  107.     notifychanged self true
  108.     value
  109. )
  110.  
  111.  
  112. method draw self {class BetterShadowedShape} surface clip ->
  113. (
  114.  local xval := self.shadowXoffset
  115.  local yval := self.shadowYoffset
  116.    if (self.fill != undefined) 
  117.        do (
  118.        local gTransform := self.transform
  119.        
  120.        --  fill the shadow
  121.        local xvala, yvala
  122.        xvala := if xval < 0 then 0 else  xval
  123.        yvala := if yval > 0 then yval else 0
  124.        translate gTransform xvala yvala
  125.        fill surface self.target clip gTransform self.shadowFill
  126.        stroke surface self.target clip gTransform self.shadowStroke
  127.        
  128.        -- now draw the target
  129.        translate gTransform (- xval) (- yval)
  130.        fill surface self.target clip gTransform self.fill
  131.        stroke surface self.target clip gTransform self.stroke
  132.        
  133.        -- restore the global transform
  134.        xvala := if xval >= 0 then 0 else xvala := xval
  135.        yvala := if yval <= 0 then yval else 0
  136.        translate gTransform xvala yvala
  137.    )
  138. )
  139.  
  140.  
  141. global w := new window
  142. w.height := 300
  143. w.width := 400
  144. show w
  145.  
  146.  
  147. global shape1 := new BetterShadowedShape \
  148.     target:(new oval x2:100 y2:100) 
  149.     
  150.     
  151. shape1.fill := new brush color:magentacolor
  152.  
  153.     
  154. shape1.x := 20
  155. shape1.y := 20
  156. prepend w shape1
  157. -->>>
  158.  
  159.  
  160.